define(function(){
	var common=
		{
			mounted:function(){
	    		this.submitJson.process_code= this.$route.query['process_code'];
	    		this.getDefaultUsers();
		    },
			data:function(){
				return{
					approve_list:null,
					cc_list:null,
					startTime:'',
				    endTime:'',
				    subFlag:false,//以下为提交comnmon
					submitJson:{
					    "process_code":'',
					    "approvers": "",
					    "cc_list": "",
					    "component": []
					}//提交comnmon  
				}
			},
			methods:{
				getApproveUsers:function(data)//提交封装审批人
	    		{
	    			this.submitJson.approvers='';
	    			if(data && data.length>0){
	    				for(var i=0,o;o=data[i++];)
	    				{
	    					if(!o.emplId)
	    					{
	    						this.submitJson.approvers='';
	    						return;
	    					}
	    					 this.submitJson.approvers+=o.emplId+',';
	    				}
	    			};
	    		},
	    		getCopyUsers:function(data)//提交封装抄送人
	    		{
	    			this.submitJson.cc_list='';
	    			if(data && data.length>0){
	    				for(var i=0,o;o=data[i++];)
	    				{
	    					 this.submitJson.cc_list+=o.emplId+',';
	    				}
	    			};
	    		},
	    		getFilefn:function(data)
	    		{ 
	    			  var arr=[],name='';
	    			  for(var i=0,o;o=data[i++];){
	    			  	 arr.push(o.file_url);
	    			  	 name=o.name;
	    			  };
    			  	  for(var i=0;i<this.submitJson.component.length;i++){
    			  	  	    var o=this.submitJson.component[i];
    			  	  	    if(o.name==name)
    			  	  	    {
    			  	  	    	this.submitJson.component.splice(i,2);
    			
    			  	  	    }
    			  	  }
    			  	  if(arr.length>0)
    			  	  {
    			  	  	 this.submitJson.component.push({
		    			  		"name":name,
	                            "value":JSON.stringify(arr)
		    			  });
    			  	  }
	    		},
	    		submitFn:function(ev)//提交
	    		{
	    			if(!sessionStorage.getItem('submitBfalg'))
	    			{
	    				sessionStorage.setItem('submitBfalg','true')
	    			}
	    			
	    			if(sessionStorage.getItem('submitBfalg')=='false')
	    			{
	    				return;
	    			}
	    			this.subFlag=true;
	    			this.$nextTick(function(){
	    				var dataList=document.querySelectorAll('[data-false]');
	    				for(var i=0;i<dataList.length;i++)
	    				{
	    					 try{
	    					 	$.toast(dataList[i].getAttribute('data-text'), "text");
	    					 	sessionStorage.setItem('submitBfalg','true');
	    					 	return false;
	    					 }catch(e){
	    					 	sessionStorage.setItem('submitBfalg','true');
	    					 	return false;
	    					 	//TODO handle the exception
	    					 }
	    				}
/*
	    				if(document.querySelectorAll('[data-false]').length>0)
	    				{
	    					return false;
	    				};*/
	    			    var arr=[];
	    			    for(var i=0,o;o=this.submitJson.component[i++];)
	    			    {
	    			    	 if(o.value!='')
	    			    	 {
	    			    	 	arr.push(o);
	    			    	 }
	    			    }
	    			    this.submitJson.component=arr;
	    			    
	    				if(/^\s*$/g.test(this.submitJson.approvers))
	    				{
	    					try{
	    						layer.msg('审批人未选择');
	    						sessionStorage.setItem('submitBfalg','true');
	    					}catch(e){
	    						$.toast('审批人未选择', "text");
	    						sessionStorage.setItem('submitBfalg','true');
	    					}
	    					return;
	    				}
	    				var _this=this;
	    				sessionStorage.setItem('submitBfalg','false');
	    				this.myAjax({
		     	 		 	 type:"post", 
		     	 		 	 tooken:false,
		     	 		 	 data:JSON.stringify(this.submitJson),
		     	 		 	 url: '/bpms/approves',
		     	 		 	 callback:function(data)
		     	 		 	 { 
		     	 		 	 	 if(data.code=='200')
		     	 		 	 	 {
		     	 		 	 	 	sessionStorage.setItem('submitBfalg','true');
		     	 		 	 	 	if (navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){
									     window.Router.push({path:'search-list',query:{'type':'started'}});
								    }else{
								    	_this.$router.push({name:'searchlist',params:{id:'started'}});
 
								    }
		     	 		 	 	 };
		     	 		 	 	 if(data.code=='400')
		     	 		 	 	 {
		     	 		 	 	 	sessionStorage.setItem('submitBfalg','true');
		     	 		 	 	 }
		     	 		 	 },
		     	 		 	 error:function()
		     	 		 	 {
		     	 		 	 	sessionStorage.setItem('submitBfalg','true');
		     	 		 	 }
		     	 		 });
	    			});
	    			
	    		},
	    		getDefaultUsers:function(extend)
    		    {
    		    	var sUrl='/bpms/default?process_code='+this.submitJson.process_code;
    		    	if(extend)
    		    	{
    		    		sUrl='/bpms/default?process_code='+this.submitJson.process_code+'&extend='+extend
    		    	}
    		    	var _this=this;
	    		  	this.myAjax({
					 	 type:"get",
	     	 		 	 tooken:false,
	     	 		 	 url:sUrl,
	                     callback:function(data){
	                     	if(data.code=='200')
	                     	{
	                     		 _this.approve_list=data.data.approve_list;
	                     		 _this.cc_list=data.data.cc_list;
	                     	}
	                     	 
	                     }
	    		  	});
    		    }
			}
	};
	return {"common":common }
});


